All Questions
9 questions
1vote
1answer
258views
Enqueue scripts all over but not in single.php
I need to insert this script in the footer on the home, in categories, in pages, in the tags in the search but NOT in single.php: function live_search() { wp_enqueue_script('live_search', ...
3votes
1answer
3kviews
How to add extra attributes to the script tag added via wp_localize_script()
So, wp_localize_script() are awesome to add custom data to a script. And these data gets added to the HTML like: <script id='woocommerce_some-js-extra' type="text/javascript"> var ...
0votes
1answer
418views
How to pass data to javascript in custom widget class
I have a custom widget where the user can insert an username in an <input> field. It's working fine, but I need to get the inserted value from php and pass it to the javascript file that is ...
0votes
1answer
81views
How to make sure, that only the selected post is changing?
So I was able to save the content of each post in an array, thanks to a very good answer on it: How to localize value of posts I just copied the solution here: function register_and_enqueue_script() ...
0votes
1answer
369views
How to localize value of posts
I've got a problem again. I scripted a little JS function, that alters content of a post. To pass the content to the function I used this: function register_and_enqueue_script() { ...
3votes
4answers
1kviews
wp_localize_script with boolean and init
I have problem with wp_localize_script, That I cannot get boolean and int as variable wp_enqueue_script( 'helloworld' , 'helloworld.js', false, '1.0.0', true); $site_config = array(); $site_config['...
1vote
1answer
707views
Script Localization doesn't work
I don't get how script localization works in wordpress. I created an associative array in php: $translations = array( 'value1' =>'This is first value', 'value2' =>'This is second ...
0votes
1answer
1kviews
Getting a variable inside foreach from PHP to JS after localization
I believe I have properly enqueue'ed and localized my script - I've got $q showing up in the DOM. Now I'm sure I'm missing the simple last step to accessing a variable in the JS function. Here's my ...
8votes
4answers
5kviews
Is there a JavaScript API? How to access public and private data in JS?
According to this post there is no built-in JavaScript API for Wordpress. Therefore developers who want to build on AJAX seem to come up all with their own solution which doesn't seem right to me. ...